// chrome.action.setBadgeText({ text: "禁用" })
chrome.runtime.onInstalled.addListener((details) => {
  // console.log(details);
  chrome.action.setBadgeText({ text: "禁用" })
})


chrome.action.onClicked.addListener(async (tab) => {
  if (tab.url.startsWith("https://developer.chrome.google.cn/docs/extensions")
    || tab.url.startsWith("https://developer.chrome.google.cn/docs/webstore")) {

    // console.log('图标被点击了') 
    const prevState = await chrome.action.getBadgeText({ tabId: tab.id })
    const nextState = prevState === '禁用' ? '启用' : '禁用'
    chrome.action.setBadgeText({ text: nextState, tabId: tab.id })

    // console.log(tab);

    if (nextState === "启用") {
      await chrome.scripting.insertCSS({
        files: ["focus-mode.css"],
        target: { tabId: tab.id },
      });
    } else if (nextState === "禁用") {
      await chrome.scripting.removeCSS({
        files: ["focus-mode.css"],
        target: { tabId: tab.id },
      });
    }
  }
})

